package com.cyz.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyz.dao.CoursedesignDao;
import com.cyz.dao.TaskbookDao;
import com.cyz.dao.WorkScoreDao;
import com.cyz.entity.CoursedesignEntity;
import com.cyz.entity.WorkScore;
import com.cyz.vo.TaskDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cyz.entity.TaskbookEntity;
import com.cyz.service.TaskbookService;




/**
 *
 *
 * @author chenyizhen
 * @email
 * @date 2023-12-26 14:18:30
 */
@RestController
@RequestMapping("taskbook")
public class TaskbookController {
    @Autowired
    private TaskbookService taskbookService;

    @Autowired
    private CoursedesignDao coursedesignDao;

    @Autowired
    private TaskbookDao taskbookDao;

    @Autowired
    private WorkScoreDao workScoreDao;

    @PostMapping("/list")
    public List<TaskDto> list(){
        List<TaskbookEntity> taskbookEntities = taskbookDao.selectList(new QueryWrapper<>());
        List<TaskDto> collect = taskbookEntities.stream().map(item -> {
            CoursedesignEntity coursedesignEntity = coursedesignDao.selectById(item.getCourseId());
            TaskDto taskDto = new TaskDto();
            taskDto.setCourseName(coursedesignEntity.getDesignName());
            taskDto.setTask(item.getDescription());
            return taskDto;
        }).collect(Collectors.toList());
        return collect;
    }

    @PostMapping("update")
    public String update(String course, String task){
        List<CoursedesignEntity> designName = coursedesignDao.selectList(new QueryWrapper<CoursedesignEntity>().eq("design_name", course));
        TaskbookEntity entity = taskbookDao.selectOne(new QueryWrapper<TaskbookEntity>().eq("course_id", designName.get(0).getId()));

        entity.setDescription(task);
        taskbookDao.updateById(entity);
        return "任务书已更新";
    }

    @PostMapping("updateScore")
    public String updateScore(int course,double task){
        WorkScore workScore = workScoreDao.selectById(course);
        workScore.setScore(task);
        workScoreDao.updateById(workScore);
        return "分数更新";
    }
    /**
     * 列表
     */
//    @RequestMapping("/list")
//    //@RequiresPermissions("user:taskbook:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = taskbookService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }
//
//
//    /**
//     * 信息
//     */
//    @RequestMapping("/info/{id}")
//    public R info(@PathVariable("id") Integer id){
//		TaskbookEntity taskbook = taskbookService.getById(id);
//
//        return R.ok().put("taskbook", taskbook);
//    }
//
//    /**
//     * 保存
//     */
//    @RequestMapping("/save")
//    public R save(@RequestBody TaskbookEntity taskbook){
//		taskbookService.save(taskbook);
//
//        return R.ok();
//    }
//
//    /**
//     * 修改
//     */
//    @RequestMapping("/update")
//    public R update(@RequestBody TaskbookEntity taskbook){
//		taskbookService.updateById(taskbook);
//
//        return R.ok();
//    }
//
//    /**
//     * 删除
//     */
//    @RequestMapping("/delete")
//    public R delete(@RequestBody Integer[] ids){
//		taskbookService.removeByIds(Arrays.asList(ids));
//
//        return R.ok();
//    }

}
